package com.example.customer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

@RestController
@RequestMapping("/api/v1/customers")
@Slf4j
public record CustomerController(CustomerService customerService) {

    @GetMapping("/health")
    public String health() {
        return "customer service is running";
    }

    @PostMapping
    public ResponseEntity<String> registerCustomer(@Valid @RequestBody CustomerRegistryRequest request) {
        log.info("接收到客户注册请求: {}", request);
        customerService.registerCustomer(request);
        return ResponseEntity.status(HttpStatus.CREATED).body("注册成功，欢迎邮件已发送");
    }

    @GetMapping("/{id}")
    public ResponseEntity<Customer> getCustomer(@PathVariable Integer id) {
        Customer customer = customerService.getCustomerById(id);
        return ResponseEntity.ok(customer);
    }
}